home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
FREENET
/
FERGUSON
/
CLIENT_P
/
!Client_Ex
/
c
/
Command
< prev
next >
Wrap
Text File
|
1995-06-05
|
5KB
|
179 lines
/*
File: Command.c
Date: 03-Jun-1995
Author: © Duncan Ferguson
File Purpose: provide window to get server Command with
Version: 0.01
*/
/* handle the command window and its button clicks */
/* ============================================================= */
/* | Include files | */
/* ============================================================= */
#include "Command.h"
#include "Connect.h"
#include "Client_Ex.h"
#include "NetLib:netdb.h"
#include "DeskLib:Error.h"
#include "DeskLib:Event.h"
#include "DeskLib:Handler.h"
#include "DeskLib:Icon.h"
#include "DeskLib:Msgs.h"
#include "DeskLib:Window.h"
#include "DeskLib:WIMP.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
/* ============================================================= */
/* | #Definitions | */
/* ============================================================= */
#define BUFFER_SIZE 1024
/* ============================================================= */
/* | Structures | */
/* ============================================================= */
/* icon numbers */
static enum {
command_HELP, /* = 0 */
command_LIST,
command_POST,
command_NEWNEWS,
command_NEWNEWS_TEXT, /* = 4 */
command_ARTICLE,
command_ARTICLE_TEXT,
command_GROUP,
command_GROUP_TEXT,
command_IHAVE,
command_SLAVE,
command_QUIT /* = 11 */
};
/* ============================================================= */
/* | Global variables | */
/* ============================================================= */
static window_handle Command_Window = 0;
/* ============================================================= */
/* | Function Prototypes | */
/* ============================================================= */
static BOOL Command_ClickHandler(event_pollblock *event, void *reference);
static BOOL Command_Delete(event_pollblock *event, void *reference);
/* ============================================================= */
/* | External functions | */
/* ============================================================= */
extern void Command_Open(void)
{
if(!Command_Window)
{
Command_Window = Window_CreateAndShow("Commands", 0, open_WHEREVER);
/* error occured in getting template */
if(Command_Window == 0)
{
Msgs_Report(0, "no.template");
return;
}
Event_Claim(event_CLOSE, Command_Window, event_ANY, Command_Delete,
&Command_Window);
Event_Claim(event_OPEN, Command_Window, event_ANY, Handler_OpenWindow,
NULL);
Event_Claim(event_CLICK, Command_Window, event_ANY, Command_ClickHandler,
NULL);
Icon_SetText(Command_Window, command_NEWNEWS_TEXT, NULL);
Icon_SetText(Command_Window, command_ARTICLE_TEXT, NULL);
Icon_SetText(Command_Window, command_GROUP_TEXT, NULL);
}
else
{
Window_BringToFront(Command_Window);
}
}
/* ============================================================= */
/* | Internal functions | */
/* ============================================================= */
static BOOL Command_ClickHandler(event_pollblock *event, void *reference)
{
char Buffer[BUFFER_SIZE+1];
char Command[BUFFER_SIZE+1];
/* kill compiler warning */
UNUSED(reference);
switch(event->data.mouse.icon)
{
case command_HELP:
sprintf(Command, "HELP\r\n\0");
break;
case command_LIST:
sprintf(Command, "LIST\r\n\0");
break;
case command_POST:
sprintf(Command, "POST\r\n\0");
break;
case command_NEWNEWS:
Icon_GetText(Command_Window, command_NEWNEWS_TEXT, Buffer);
sprintf(Command, "NEWNEWS %s\r\n\0", Buffer);
break;
case command_ARTICLE:
Icon_GetText(Command_Window, command_ARTICLE_TEXT, Buffer);
sprintf(Command, "ARTICLE %s\r\n\0", Buffer);
break;
case command_GROUP:
Icon_GetText(Command_Window, command_GROUP_TEXT, Buffer);
sprintf(Command, "GROUP %s\r\n\0", Buffer);
break;
case command_IHAVE:
sprintf(Command, "IHAVE\r\n\0");
break;
case command_SLAVE:
sprintf(Command, "SLAVE\r\n\0");
break;
case command_QUIT:
sprintf(Command, "QUIT\r\n\0");
break;
}
if(!Connect_SendMessage(Command))
{
Error_Report(0, "The message could not be sent for some reason");
}
return TRUE;
}
static BOOL Command_Delete(event_pollblock *event, void *reference)
{
window_handle *window = reference;
assert(event->data.openblock.window == *window);
/* make sure window handles match */
Window_Delete(event->data.openblock.window);
*window = 0;
return TRUE;
}